<template>
	<view>
		<view class="setinfo">
			<u-form :model="user" ref="uForm">
				<u-form-item label="座右铭" label-width="150"><u-input v-model="user.userMotto" /></u-form-item>
			</u-form>
		</view>
		<button class="CommentBtn" @click="updateUser">确认修改</button>
		<!-- 语句提示 -->
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import { updateuser } from '../../api/user.js'
	export default {
		data() {
			return {
			  user: {},
			}
		},
		created() {
			this.user = this.$store.state.userinfo
		},
		methods: {
		  // 更新用户信息
		  async updateUser () {
			  const params = {
				  userId: this.user.userId,
				  userMotto: this.user.userMotto
			  }
			  const res = await updateuser(params)
			  if (res.statusCode == 200) {
				 this.$store.dispatch('getUserInfo')
				  uni.navigateBack({
				  	delta: 1,
				  })
			  } else {
				 this.$refs.uToast.show({
				 	type: 'error',
				 	title: '用户信息更新失败'
				 }) 
			  }
		  }
		}
	}
</script>

<style lang="less">
/* 表单样式 */
.setinfo {
	margin-top: 36rpx;
	background-color: #fff;
	padding:  0 24rpx;
	image {
		width: 120rpx;
		height: 120rpx;
		border-radius: 6rpx;
		margin-left: 124rpx;
	}
	}
</style>
